<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" >

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-3.3.7-dist/css/bootstrap.min.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-treeview/bootstrap-treeview.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-treeview/bootstrap-treeview.min.css}">
<script type="text/javascript" th:src="@{/js/bootStrap-addTabs/bootstrap.addtabs.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootStrap-addTabs/bootstrap.addtabs.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-table/bootstrap-table.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-table/bootstrap-table.min.css}">
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-fileinput/css/fileinput.css}">

<script type="text/javascript" th:src="@{/js/bootstrap-bootbox/bootbox.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput/js/locales/zh.js}"></script>

<body>
<div>
    <button type="button" class="btn btn-primary"
            data-toggle="modal" data-target="#addLayer">添加类型</button>
</div>
<table id="myTable"></table>


<!--记录添加弹出层 -->
<div class="modal fade" id="addLayer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">

                <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">添加类型</h4>

            </div>
            <!--=========================================================================================  -->
            <div class="modal-body">
                <form id="myForm">
                    类型名称：<input type="text" class="form-control" name="typename"   placeholder="类型名称">

                </form>
            </div>
            <!--=========================================================================================  -->
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary" type="button" onclick="add()">确认添加</button>
            </div>

        </div>
    </div>
</div>

<!--  --><!--   --><!--   -->
<script type="text/javascript">
    function add(){
        $.ajax({
            url:"Type",
            type:"post",
            data:$("#myForm").serialize(),
            success:function(){
                alert("成功")
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#addLayer").modal('hide');
            }
        })
    }


    /**/
    $("#myTable").bootstrapTable({
        url:"getType",
        columns:[
            {field:"xuan",checkbox:true},
            {field:"id",title:"编号"},
            {field:"typename",title:"商品类型"},
            {field:"cxz",title:"操作",formatter:function(value,row){
                    var str='<button class="btn btn-info" onclick="del('+row.id+')">删除</button>';
                    return str;
                }},
        ],
        pagination:true,
        pageSize:10,
        pageList:[2,4,6,8,10],
        sidePagination: "client",
        toolbar:"#tb",
    })

    function del(id) {

        $.ajax({
            url:"delType",
            data:{id:id},
            success:function(){
                alert("成功")
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#addLayer").modal('hide');
            }
        })

    }
</script>
</body>
</html>